Implement RTL8139 Driver#81
Conversation
src/kernel/arch/riscv64/include.mak
Outdated
| bgdb: src/kernel/kernel.sym | ||
| gdb-multiarch src/kernel/kernel.sym \ | ||
| -ex "set substitute-path / $(srcdir)/" \ | ||
| -ex "target remote :1234" | ||
|
|
There was a problem hiding this comment.
True, this is another personal change that I will keep that way in the final version, but I sometimes don't use the tui so it helps to have a shortcut
| /** | ||
| * An Sv39 page table entry. | ||
| */ | ||
|
|
There was a problem hiding this comment.
This all changed dramatically in #50; sorry for the breakage.
There was a problem hiding this comment.
I'll take this as a good chance to make my code a bit cleaner, which includes merging the new trunk into my branch, so my code will use the new mm then
There was a problem hiding this comment.
I'd advise rebase instead of merge, but 👍 in general.
(It probably shouldn't matter if you're just doing it from trunk, but rebase keeps the semantics of "my branch is a series of patches off of some version of trunk" instead of the more annoying truth of "my branch is a dag of repo states"...)
src/kernel/drivers/rtl8139.c
Outdated
| #define READ_U8(addr, off) physical_read_u8(paddr_of_bits(addr + off)) | ||
| #define WRITE_U8(addr, off, value) physical_write_u8(paddr_of_bits(addr + off), value) | ||
|
|
||
| #define READ_U16(addr, off) physical_read_u16le(paddr_of_bits(addr + off)) | ||
| #define WRITE_U16(addr, off, value) physical_write_u16le(paddr_of_bits(addr + off), value) | ||
|
|
||
| #define READ_U32(addr, off) physical_read_u32le(paddr_of_bits(addr + off)) | ||
| #define WRITE_U32(addr, off, value) physical_write_u32le(paddr_of_bits(addr + off), value) |
There was a problem hiding this comment.
This is probably a bug against physical.c, but note that these currently to not have READ_ONCE/WRITE_ONCE semantics. The problem comes up in code like this:
WRITE_U32(a, 0, 1);
while (READ_U32(a, 4))
;
WRITE_U32(a, 0, 0);The compiler is perfectly within its rights to optimize this to:
while (READ_U32(a, 4))
;
WRITE_U32(a, 0, 0);In general, I'm pretty "ehhh" on these helpers -- they should probably use paddr_offset, but also if they're convenient enough that you need them, they're probably convenient enough to add to physical.h.
Probably the right thing here is to make the physical_ functions have those semantics, but I think you probably actually want to:
- Discover the device from PCI (see Device model #70).
- Allocate a VMA to map the PCI device's registers.
- Map the device's registers to that VMA with
iomem_map, casting the pointer to a pointer to a struct for the registers. - Use a "real"
READ_ONCE/WRITE_ONCEmacro to access the fields of that device.
We don't have those real READ_ONCE/WRITE_ONCE macros, so... I should do that.
There was a problem hiding this comment.
Correct, these are not meant to be READ/WRITE_ONCE, but rather a simple way for me to do physical reads and writes with u64s (it works on my machine, so I figured I'd deal with READ/WRITE_ONCE later). Is this good? Not really, but once I can map in a physical address, I was planning on having a nice register struct, so instead of
WRITE_REG_32(REG_COM, COM_TE)
we just do something sort of like
rtl->com = COM_TE
(or using WRITE_ONCE ofc, but same idea) which means that these helpers aren't required
Also, I am not sure how this is exactly related to the PCI part, but the PCI "driver" will be rewritten to load data from the device tree so there won't be any hardcoded physical addresses.
There was a problem hiding this comment.
👍 For PCI, I just meant reading from/writing to PCI registers
There was a problem hiding this comment.
Ah gotcha, then yeah the new PCI driver will also use the same better method as the rtl8139 driver itself, meaning little to no READ/WRITE_U32 or similar
| } | ||
|
|
||
|
|
||
| void rtl8139_test() { |
There was a problem hiding this comment.
Oh hm, my first instinct would be to say "make this a selftest," but we don't want selftests that depend on the user having certain hardware either...
This probable deserves some thought.
Should this be exposed to userspace, so we can hit it in CI (maybe this would be a build time option, see #62)? Should we accumulate a list of selftests for devices (not drivers) and allow this to be run later in boot?
There was a problem hiding this comment.
yeah, I tried a selftest and realized that myself, I had thought of some sort of devices selftest, but I don't want to create too many different types of selftest, so I would be in favor of exposing to userspace and having some userspace testing
src/kernel/main.c
Outdated
| mm_init_virtual(free_va_start, free_va_end); | ||
| pci_enumerate(); | ||
|
|
||
| wfi(); |
There was a problem hiding this comment.
wait for interrupt, I probably shouldn't have committed this but I didn't like the busy loops (my fans turn on)
There was a problem hiding this comment.
er yeah, I just meant "why" -- is this just to halt the machine completely?
There was a problem hiding this comment.
It's probably worth mentioning that the change to main.c is really just to get the code to do anything interesting at all, but in the future the PCI will be initialized from the device tree, meaning no call to pci_enumerate in main.c
src/kernel/pci.c
Outdated
| paddr mad(u64 addr) { | ||
| paddr *x; | ||
| x = (paddr*) (&addr); | ||
| return *x; | ||
| } |
There was a problem hiding this comment.
a poor hack that I made for some reason when I wrote PCI - most of PCI will be rewritten, but that will take a bit more time (for now, I wanted the rtl8139 part to be seen by people)
There was a problem hiding this comment.
ah, okay; i think the same bullet points for physical memory access as above probably apply to it, though i agree "push something" > "the code is in its final state" (esp. given that the stuff i'm saying to use is just-merged :p )
There was a problem hiding this comment.
You're right, and I left a note in #70 about where to include changes to PCI but yeah, this is really just a fix in code that shouldn't really be in trunk anyways
rebase kieran off non-nonsense Signed-off-by: jastintime <130672671+jastintime@users.noreply.github.com>
43ee3d2 to
74c2d24
Compare
Quite basic and the branch is behind the trunk. I'm making this so people can at least look at the header and comment before anything is final.
Only transmit is implemented, receive is waiting on interrupts and more.